###########################################################
#     Prj: WGCNA all in one
#     Assignment: out Cytoscape
#     Author: Shawn Wang
#     Date: Mar 24,2021
###########################################################
suppressMessages(library(WGCNA))
suppressMessages(library(getopt))
load("step2.Rdata")
# args --------------------------------------------------------------------
command=matrix(c(
  'help', 'h', 0, 'logic', 'help information',
  'sml', 's', 1, 'character', 'which module do you want to select',
  'threshold', 't', 1, 'double', 'threshold of weights'
),byrow = T, ncol = 5)
args = getopt(command)

## default valuels==========
if (!is.null(args$help)) {
  cat(paste(getopt(command, usage = T), "\n"))
  #  q(status=1)
}
if (is.null(args$sml)){
  q(status = 1)
}
if (is.null(args$threshold)){
  threshold = 0.02
}
sml = args$sml
threshold = args$threshold
cyt = cytoscapeout(datExpr = datExpr,power = powerIn,module = sml,moduleColors = moduleColors,threshold = threshold)

write.table(x = cyt[[1]],paste0("06.",sml,".cyt.edgefile.xls"),row.names = F,sep = "\t",quote = F)
write.table(x = cyt[[2]],paste0("06.",sml,".cyt.nodefile.xls"),row.names = F,sep = "\t",quote = F)